a = input().split()
b = ''
n = 0
mn = 0
mx = 0
p = 0
c, d = 0, 0
for i in a:
    if i == 'zero':
        b += '0'
    elif i == 'one':
        b += '1'
    elif i == 'two':
        b += '2'
    elif i == 'three':
        b += '3'
    elif i == 'four':
        b += '4'
    elif i == 'five':
        b += '5'
    elif i == 'six':
        b += '6'
    elif i == 'seven':
        b += '7'
    elif i == 'eight':
        b += '8'
    elif i == 'nine':
        b += '9'
if len(b) != 3:
    print('Wrong input')
else:
    n = int(b)
    for x in range(n, 0, -1):
        for i in range(2, x):
            if x % i == 0:
                p += 1
                break
        if p == 0:
            mn = i
            break
        else:
            p = 0
    for x in range(n, 10 ** 10):
        for i in range(2, x):
            if x % i == 0:
                p += 1
                break
        if p == 0:
            mx = i
            break
        else:
            p = 0
    c = mx - n
    d = n - mn
    if c < d:
        print(mx)
    else:
        print(mn)
                
        
    
